package com.sos.widget.binding;

import android.content.res.ColorStateList;
import android.graphics.Paint;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;

import com.sos.widget.util.RichTextUtils;

/**
 * @Description
 * @Author 梁浩文
 * @Date 2022/8/26 9:58
 */
public class TextViewBinding {

    @BindingAdapter(value = {"saas_textColor", "saas_rich_text", "saas_drawable_tint", "saas_text_paint"}, requireAll = false)
    public static void textBinding(TextView textView, int textColor, String richText, int tintColor, int paintType) {
        if (textView != null) {
            if (textColor != 0) {
                textView.setTextColor(textColor);
            }
            if (!TextUtils.isEmpty(richText)) {
                //富文本
                RichTextUtils.showRichHtmlWithImageContent(textView, richText);
            }
            if (tintColor != 0) {
                textView.setCompoundDrawableTintList(ColorStateList.valueOf(tintColor));
            }
            if (paintType == 0) {
                textView.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG);
            } else {
                textView.getPaint().setFlags(paintType);
            }
        }
    }

}
